package com.yc.so.demo.font;

import com.jfoenix.controls.JFXTextField;
import javafx.application.Application;
import javafx.event.EventType;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.Border;
import javafx.scene.layout.HBox;
import javafx.scene.paint.Color;
import javafx.scene.paint.CycleMethod;
import javafx.scene.paint.LinearGradient;
import javafx.scene.paint.Stop;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.stage.Stage;
import javafx.stage.StageStyle;

import java.util.HashMap;
import java.util.Map;

public class SoMain extends Application {
    private static final Font GLYPH_FONTAWESOME = Font.loadFont(Main1.class.getResourceAsStream("iconfont.ttf"), -1);
    private static final Map<String, Character> GLYPH_MAP;


    static {
        GLYPH_MAP = new HashMap<String, Character>();
        //反馈
        GLYPH_MAP.put("icon-comments", '\ue6f2');
        //设置
        GLYPH_MAP.put("icon-set", '\ue70a');
        //搜索
        GLYPH_MAP.put("icon-search", '\ue70b');
        //刷新
        GLYPH_MAP.put("icon-exchangerate", '\ue712');
        //关闭
        GLYPH_MAP.put("icon-close", '\ue6f0');
    }
    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage stage) {
        AnchorPane anchorPane=new AnchorPane();
        anchorPane.setStyle("-fx-background-color: #05050D;");
        HBox icon=new HBox();
        icon.setPrefWidth(652);
        icon.setPrefHeight(25);
        icon.setAlignment(Pos.BASELINE_RIGHT);
        icon.setPadding(new Insets(4));
        icon.setSpacing(5);
        icon.getChildren().addAll(createLable("icon-exchangerate", 2),createLable("icon-set",2),
                createLable("icon-comments",2),createLable("icon-close",2));
        HBox so=new HBox();
        so.setPrefWidth(652);
        so.setPrefHeight(47);
        so.setLayoutY(25);
        Label label=createLableNoEvent("icon-search",2);
        label.setStyle("-fx-padding:8 2 7 0;-fx-border-width: 2;-fx-border-style: hidden hidden solid;-fx-border-color: #393A45;");

        so.setStyle("-fx-padding:0 0 0 20");
        JFXTextField field = new JFXTextField();
        field.setLabelFloat(false);
        field.setPromptText("搜索本地程序、文件、文件夹");
        field.setPrefHeight(25);
        field.setPrefWidth(460);
        field.setStyle("-fx-text-inner-color: #fff;-fx-font-size: 16px;-jfx-focus-color:#363743;");
        field.focusedProperty().addListener((obs, oldVal, newVal) ->{
            System.out.println(newVal ? "Focused" : "Unfocused");
            if (newVal){

            }else {

            }
        });

        System.out.println(field.getBorder());
        TextField field1=new TextField();
        field1.setPrefHeight(25);
        field1.setPrefWidth(450);
        field1.setOpacity(0.5);

        so.getChildren().addAll(label,field);


        anchorPane.getChildren().addAll(icon,so);
        Scene scene=new Scene(anchorPane);
        stage.setScene(scene);
        stage.setWidth(652);
        stage.setHeight(72);
        stage.initStyle(StageStyle.TRANSPARENT);
        stage.show();
    }

    public Label createLable(String glyphName, int sizeFactor){
        Font font = Font.font(GLYPH_FONTAWESOME.getFamily(), 8 * sizeFactor);
        Label label=new Label();
        label.setFont(font);
        label.setText(String.valueOf(GLYPH_MAP.get(glyphName)));
        Stop[] stops = new Stop[]{new Stop(0, Color.web("rgb(132,132,139)"))};
        LinearGradient lg1 = new LinearGradient(0, 0, 1, 0, true, CycleMethod.NO_CYCLE, stops);

        Stop[] wit = new Stop[]{new Stop(0, Color.WHITE)};
        LinearGradient lg1w = new LinearGradient(0, 0, 1, 0, true, CycleMethod.NO_CYCLE, wit);
        label.setTextFill(lg1);
        label.addEventFilter(MouseEvent.MOUSE_ENTERED, event -> {
            label.setTextFill(lg1w);
        });
        label.addEventFilter(MouseEvent.MOUSE_EXITED, event -> {
            label.setTextFill(lg1);
        });
        return label;   
    }

    public Label createLableNoEvent(String glyphName, int sizeFactor){
        Font font = Font.font(GLYPH_FONTAWESOME.getFamily(), 8 * sizeFactor);
        Label label=new Label();
        label.setFont(font);
        label.setText(String.valueOf(GLYPH_MAP.get(glyphName)));
        Stop[] wit = new Stop[]{new Stop(0, Color.WHITE)};
        LinearGradient lg1w = new LinearGradient(0, 0, 1, 0, true, CycleMethod.NO_CYCLE, wit);
        label.setTextFill(lg1w);
        return label;
    }


}
